<div class="cashes view">
    <h2><?php __('Caja del día ' . date('d/m/Y', strtotime($cash['Cash']['date_open']))); ?></h2>
    <dl>
        <?php
        $i = 0;
        $class = ' class="altrow"';
        ?>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Id'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <?php echo $cash['Cash']['id']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Usuario que la abrió'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <?php echo $this->Html->link($cash['User']['name'], array('controller' => 'users', 'action' => 'view', $cash['User']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Monto Inicial'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <?php echo '$' . $cash['Cash']['open_amount']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Entradas'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <span id="span_total_entradas"></span>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Salidas'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <span id="span_total_salidas"></span>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Monto Final'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <?php echo '$' . $cash['Cash']['actual_amount']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Fecha de apertura'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <?php echo date('d/m/Y H:i:s', strtotime($cash['Cash']['date_open'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Última Modificación'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
            <?php echo date('d/m/Y H:i:s', strtotime($cash['Cash']['modified'])); ?>
            &nbsp;
        </dd>
    </dl>
</div>
<div class="actions specific">
    <h3><?php __('Acciones'); ?></h3>
    <ul>
        <li><?php echo $this->Html->link(__('Agregar Movimiento Simple', true), array('controller' => 'cash_movements', 'action' => 'add')); ?> </li>
        <?php
        //si estoy viendo la caja actual le permito que pueda transferir dinero a la caja grande
        if ($actual == 'si') {
            ?>
            <li><?php echo $this->Html->link(__('Pasar a Caja Grande', true), array('controller' => 'big_cash_movements', 'action' => 'importar_desde_caja_chica')); ?> </li>
            <?php
        }
        ?>
    </ul>
</div>
<div class="related">
    <h3><?php __('Movimientos Relacionados'); ?></h3>
    <?php
    $total_entradas = 0;
    $total_salidas = 0;

    if (!empty($cash['CashMovement'])):
        ?>
        <table cellpadding = "0" cellspacing = "0">
            <tr>
                <th><?php __('Quien'); ?></th>
                <th><?php __('Acción'); ?></th>
                <th><?php __('Monto'); ?></th>
                <th><?php __('Tipo'); ?></th>
                <th><?php __('Hora'); ?></th>
                <th class="actions"><?php __('Acciones'); ?></th>
            </tr>
            <?php
            $i = 0;
            foreach ($cash['CashMovement'] as $cashMovement):
                $class = null;
                if ($i++ % 2 == 0) {
                    $class = ' class="altrow"';
                }
                ?>
                <tr<?php echo $class; ?>>
                    <td><?php echo $users[$cashMovement['user_id']]; ?></td>
                    <td>
                        <?php
                        if ($cashMovement['type'] == 'in') {
                            $tipo = 'Entrada';
                            $total_entradas += $cashMovement['amount'];
                        } else {
                            $tipo = 'Salida';
                            $total_salidas += $cashMovement['amount'];
                        }
                        echo $tipo;
                        ?>
                    </td>
                    <td><?php echo '$' . $cashMovement['amount']; ?></td>
                    <td>
                        <?php
                        switch ($cashMovement['movement']) {
                            case 'simple':
                                $movimiento = 'Simple';
                                break;
                            case 'sign':
                                $movimiento = 'Seña';
                                break;
                            case 'employee':
                                $movimiento = 'Pago Empleado ' . $employees[$cashMovement['employee_id']];
                                break;
                            case 'provider':
                                $movimiento = 'Pago Proveedor ' . $providers[$cashMovement['provider_id']];
                                break;
                            case 'expense':
                                $movimiento = 'Pago Gasto';
                                break;
                            case 'birthday':
                                $movimiento = 'Pago Trabajo';
                                break;
                            case 'transfer_cash':
                                $movimiento = 'Transferencia Caja Grande ('. $this->Html->link('Ver Movimiento', array('controller' => 'big_cash_movements', 'action' => 'view', $cashMovement['big_cash_movement_id'])).')';
                                break;
                            case 'job_payment':
                                $movimiento = 'Pago Saldo Trabajo';
                                break;
                            default:
                                $movimiento = '';
                                break;
                        }
                        echo $movimiento;
                        ?>
                    </td>
                    <td><?php echo date('H:i:s', strtotime($cashMovement['created'])); ?></td>
                    <td class="actions">
                        <?php
                        if ($cashMovement['job_id'] != '') {
                            echo $this->Html->link($this->Html->image('icons/magnifier.png'), array('controller' => 'jobs', 'action' => 'view', $cashMovement['job_id']), array('title' => __('Ver Detalle', true), 'escape' => false));
//                        }elseif ($cashMovement['theater_id'] != '') {
//                            echo $this->Html->link($this->Html->image('icons/magnifier.png'), array('controller' => 'theaters', 'action' => 'view', $cashMovement['theater_id']), array('title' => __('Ver Detalle', true), 'escape' => false));
                        } elseif ($cashMovement['expense_id'] != '') {
                            echo $this->Html->link($this->Html->image('icons/magnifier.png'), array('controller' => 'expenses', 'action' => 'view', $cashMovement['expense_id']), array('title' => __('Ver Detalle', true), 'escape' => false));
                        } else {
                            echo $this->Html->link($this->Html->image('icons/magnifier.png'), array('controller' => 'cash_movements', 'action' => 'view', $cashMovement['id']), array('title' => __('Ver Detalle', true), 'escape' => false));
                        }
                        ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </table>
        <?php
    endif;
    echo $this->Form->input('total_entradas', array('type' => 'hidden', 'value' => $total_entradas));
    echo $this->Form->input('total_salidas', array('type' => 'hidden', 'value' => $total_salidas));
    ?>
</div>
<script type="text/javascript">
    $().ready(function(){
        //cargo los valores de los totales en la partes d arriba de los span
        var total_entradas = $('#total_entradas').val();
        $('#span_total_entradas').html('$'+total_entradas)
        var total_salidas = $('#total_salidas').val();
        $('#span_total_salidas').html('$'+total_salidas)
    });
</script>
